﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;


namespace shfa.snomtastic.systray.components
{
    public class AboutToast
    {

        private TaskbarNotifier tbAbout;
        private Timer timer = new Timer();
        private TaskButton aboutButton;
        private Font TitleFont;
        private Font NormalFont;

        public AboutToast()
        {
            MakeToast();
            timer.Interval = 5000;
            timer.Tick += new EventHandler(timer_Tick);
        }
        

        void timer_Tick(object sender, EventArgs e)
        {
            this.Hide();
        }


        private void MakeToast()
        {
            Assembly asm = Assembly.GetExecutingAssembly();

            tbAbout = new TaskbarNotifier();

            Bitmap bUp = new Bitmap(asm.GetManifestResourceStream("shfa.snomtastic.systray.images.AboutUp.bmp"));
            Bitmap bDown = new Bitmap(asm.GetManifestResourceStream("shfa.snomtastic.systray.images.AboutDown.bmp"));
            Bitmap bOver = new Bitmap(asm.GetManifestResourceStream("shfa.snomtastic.systray.images.AboutOver.bmp"));

            tbAbout.SetBackgroundBitmap(bUp, Color.FromArgb(255, 0, 255));

            aboutButton = new TaskButton(bUp, bDown, bOver);

            aboutButton.Left = 0;
            aboutButton.Top = 0;
            aboutButton.Height = tbAbout.Height;
            aboutButton.Width = tbAbout.Width;

            tbAbout.Controls.Add(aboutButton);

            aboutButton.Click += new EventHandler(aboutButton_Click);


            TitleFont = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold, GraphicsUnit.Point);
            NormalFont = new Font(FontFamily.GenericSansSerif, 9, FontStyle.Regular, GraphicsUnit.Point);

        }

       

        protected void aboutButton_Click(object sender, EventArgs e)
        {
            this.Hide();

        }

        public void Hide()
        {
            timer.Stop();
            tbAbout.Fade();
            
        }


        public void Show(string title, string product, string description, string userName, string phoneIp, DateTime lastCheck)
        {
            if (tbAbout.TaskbarState == TaskbarNotifier.TaskbarStates.hidden)
            {

                List<TextItem> TextItems = new List<TextItem>();
                TextItems.Add(new TextItem(title, TitleFont, Color.FromArgb(142, 0, 0), new Point(3, 3)));
                TextItems.Add(new TextItem(product, NormalFont, Color.FromArgb(0, 0, 0), new Point(3, 18)));
                TextItems.Add(new TextItem(description, NormalFont, Color.FromArgb(0, 0, 0), new Point(3, 33)));
                TextItems.Add(new TextItem("User: " + userName, NormalFont, Color.FromArgb(255, 255, 255), new Point(3, 55)));
                TextItems.Add(new TextItem("Phone: " + phoneIp, NormalFont, Color.FromArgb(255, 255, 255), new Point(3, 70)));
                TextItems.Add(new TextItem("Last Check: " + lastCheck.ToString(), NormalFont, Color.FromArgb(255, 255, 255), new Point(3, 85)));

                aboutButton.TextItems = TextItems;

                TextItems = null;

                tbAbout.Show(250, 3000, 250);
                timer.Start();
            }
            else
            {
                this.Hide();
            }


        }

    
    }
}
